﻿using B.MES.Customer.Application.IApplication;
using B.MES.Customer.Domain;
using B.MES.Customer.Domain.DTO;
using B.MES.Customer.Infrastructure.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B.MES.Customer.Application.Application
{
    /// <summary>
    /// 销售服务实现层
    /// </summary>
    public class SalesManagementApplication : BaseApplication<SalesManagement>, ISalesManagementApplication
    {
        private readonly ISalesManagementRepository _salesManagementRepository;
        
        public SalesManagementApplication(ISalesManagementRepository salesManagementRepository) : base(salesManagementRepository)
        {
            _salesManagementRepository = salesManagementRepository;
        }
        /// <summary>
        /// 销售添加
        /// </summary>
        /// <param name="sales"></param>
        /// <returns></returns>
        public APIResult<SaleDto> AddSale(SaleDto sales)
        {

           return _salesManagementRepository.AddSale(sales);
        }
        /// <summary>
        /// 销售单删除
        /// </summary>
        /// <param name="SaleId"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public APIResult<SalesManagement> DeleteSale(int SaleId)
        {
           return _salesManagementRepository.DeleteSale(SaleId);
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public APIResult<List<SalesManagement>> DeletesSale(List<SalesManagement> list)
        {
            return _salesManagementRepository.DeletesSale(list);
        }

        /// <summary>
        /// 获取客户信息
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// <summary>
        public List<Client> GetClients()
        {
           return _salesManagementRepository.GetClients();
        }
        /// <summary>
        /// 销售反填
        /// </summary>
        /// <param name="SaleId"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>

        public SalesManagement GetSaleInfo(int SaleId)
        {
            var result=_salesManagementRepository.GetSaleInfo(SaleId);
            return result;
        }

        /// <summary>
        /// 获取销售信息
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public PageApiResut<SaleDto> GetSalesManagement(int PageIndex, int PageSize, string? LinkMan, int? ClientId)
        {
            var result=_salesManagementRepository.GetSalesManagement(PageIndex, PageSize, LinkMan, ClientId);
            return result;
        }
        /// <summary>
        /// 销售修改
        /// </summary>
        /// <param name="sales"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public int UpdateSale(SalesManagement sales)
        {
            return _salesManagementRepository.UpdateSale(sales);
        }

        /// <summary>
        /// 销售统计
        /// </summary>
        /// <returns></returns>
        public List<SalesManagementDTO> CountSale()
        {
            try
            {
               return _salesManagementRepository.CountSale(); 
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }
    }
}
